package com.young.servicehosp.controller;

import com.young.commonutil.result.Result;
import com.young.model.model.hosp.Department;
import com.young.model.model.hosp.Hospital;
import com.young.servicehosp.service.DepartmentService;
import com.young.servicehosp.service.HospitalService;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.sql.ResultSet;

@Api(tags = "医院管理API接口")
@RestController
@RequestMapping("/api/hosp")
public class HospitalController {
    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private DepartmentService departmentService;

    @PostMapping("saveHospital")
    public Result saveHospital(@Valid @RequestBody Hospital hospital) {
        //传输过程中“+”转换为了“ ”，因此我们要转换回来
        String logoDataString = hospital.getLogoData();
        if (!StringUtils.isEmpty(logoDataString)) {
            String logoData = logoDataString.replaceAll("", "+");
            hospital.setLogoData(logoData);
        }
        hospitalService.saveHospital(hospital);

        return Result.ok();
    }

    @PostMapping("saveDepartment")
    public Result saveDepartment(@Valid @RequestBody Department department) {
        departmentService.saveDepartment(department);

        return Result.ok();
    }


}
